﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            ViewState["GoBackTo"] = Request.UrlReferrer;
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        bussiness bus = new bussiness();

        if (bus.checkNull(txtUsername.Text) || bus.checkNull(txtPassword.Text))
        {
            lblError.Text = "must is not null";
        }
        else
        {
            Customer c = bus.checkLogin(txtUsername.Text, txtPassword.Text);
            if (c != null)
            {
                Session["customer"] = c;
                if (ViewState["GoBackTo"] == null)
                {
                    Response.Redirect("Default.aspx");
                }
                else 
                {
                    Response.Redirect(ViewState["GoBackTo"].ToString());
                }
                
                //Response.Redirect(Request.RawUrl);
                ////Response.Redirect("Default.aspx");

            }
            else
            {
                lblError.Text = "username or pass not valid";
            }
        }
    }
}